import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/*
    反射Student类当中的所有Field

 */
public class ReflectTest03 {
    public static void main(String[] args) throws ClassNotFoundException {
        Class studentClass = Class.forName("Student");

        //获取类中public修饰的Field
        Field[] fields = studentClass.getFields();
        System.out.println(fields.length);
        System.out.println(fields[0].getName());

        //获取所有的Field
        Field[] fields1 = studentClass.getDeclaredFields();
        System.out.println(fields1.length);
        System.out.println("*************************************");

        //遍历
        for (Field fields2: fields1) {
            //获取属性的修饰符列表
            int i = fields2.getModifiers();
            System.out.print(i + " ");//将这个代号换成“字符串”
            String modifierString = Modifier.toString(i);
            System.out.print(modifierString + " ");
            //获取属性的类型
            Class fieldType = fields2.getType();
            System.out.print(fieldType.getName() + " ");
            //获取属性的名
            System.out.print(fields2.getName() + " ");
            System.out.println();
        }
    }
}
//反射属性field
class Student{
    //field就是属性/成员
    private String name;  //Field对象
    protected int age;
    boolean sex;
    public int no;
}